package main

import (
	"fmt"
	"math"
	"slices"
	"strconv"
)

func newReverse(x int) int {
	s := strconv.Itoa(x)
	bArray := []byte(s)
	slices.Reverse(bArray)
	num, _ := strconv.Atoi(string(bArray))
	if num <= math.MinInt32 || num >= math.MaxInt32 {
		return 0
	}
	return num
}

func reverse(x int) int {
	if x > 0 {
		return newReverse(x)
	} else {
		x = 0 - x
		return 0 - newReverse(x)
	}
}
func main() {
	fmt.Println(reverse(-123))
	fmt.Println(reverse(321))
}
